/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "WorldMap.h"
#include "WOWArchive.h"

namespace PQGame
{
	WorldMap::WorldMapMap WorldMap::_maps;
	WorldMap::WorldMap(int index)
		: _index(index)
	{
		_tileManager=new MapTileManager(_index);
	}

	WorldMap* WorldMap::getWorldMap(int index)
	{
		WorldMapMap::iterator it=_maps.find(index);
		if(it!=_maps.end()){
			return it->second;
		}
		
		WorldMap* map=new WorldMap(index);
		_maps.insert(WorldMapMap::value_type(index,map));
		return map;
	}

	void WorldMap::enterTile(int col,int row)
	{
		_col=col;
		_row=row;
		_tileManager->enterTile(col,row);
	}


	void WorldMap::update(float deltaT)
	{
		_tileManager->update(deltaT);

		//according to camera,decide which tile to load
		/*
		int col=camera->getPosition().x/TILE_SIZE;
		int row=camera->getPosition().z/TILE_SIZE;
		enterTile(col,row);
		*/
	}

	float WorldMap::getTileXPos()
	{
		return _col*TILE_SIZE;
	}

	float WorldMap::getTileZPos()
	{
		return _row*TILE_SIZE;
	}

	float WorldMap::getTileMaxYPos()
	{
		return _row*TILE_SIZE;
	}

}
